CONST iIN_QUEUE% = 100
CONST iIE_OPEN% = -2
CONST WN_SUCCESS = 0
CONST WN_DEVICE_ERROR = 53
CONST WN_CONNECTION_CLOSED = 54
DECLARE FUNCTION ActionDetectPrintMgr() AS INTEGER
DECLARE FUNCTION ActionDetectPrinter() AS STRING
DECLARE FUNCTION ActionDetectPorts() AS INTEGER
DECLARE SUB CheckCartCode
DECLARE FUNCTION EditPrinterConfigInfo(a&) AS INTEGER
DECLARE FUNCTION CompareVersion(lCode&, InstPrinterName$, InstPort$) AS INTEGER
DECLARE SUB GetSepVersion(a&, b%, c%)
FUNCTION ActionDetectPrintMgr() STATIC AS INTEGER
sz$ = GetIniKeyString (INI_WININI$, INI_WINDOWS$, INI_SPOOLER$)
IF UCASE$(sz$) = UCASE$(INI_YES$) THEN
InstallPM% = YES%
IniKeySpooler% = 3
ELSEIF InstallPM% <> YES% THEN
IniKeySpooler% = DlgNoPrintMgr()
ELSE
IniKeySpooler% = 1
END IF
sz$ = ActionDetectPrinter()
IF UCASE$(sz$) = UCASE$(INI_YES$) THEN
CheckCartCode
ActionDetectPrintMgr = AUTO_INSTALL
ELSE
ActionDetectPrintMgr = PRINTER_SOURCE
END IF
sz$ = ""
END FUNCTION
FUNCTION ActionDetectPrinter STATIC AS STRING
DIM bDoDetectPrinter%
FInitInfoDialog
SetSymbolValue SYM_JCOMM_RETRYS$, "3"
RemoveSymbol SYM_STATUSITEMSTEXT$
bDoDetectPrinter = TRUE
WHILE bDoDetectPrinter
CursorSave% = ShowWaitCursor()
sz$ = UIStartDlg(DLL_CUIDLL$, JUMBO_WAITING, "FInfoDlgProc", HELP_PORT_SEARCH, "FHelpDlgProc")
sz$ = UCASE$( sz$ )
RestoreCursor CursorSave%
CursorSave% = 0
SELECT CASE UCASE$(sz$)
CASE UCASE$(INI_YES$)
bDoDetectPrinter = FALSE
CASE UCASE$(INI_NO$)
bDoDetectPrinter = FALSE
CASE UCASE$(BTN_YES$)
bDoDetectPrinter = FALSE
CASE UCASE$(BTN_NO$)
bDoDetectPrinter = FALSE
CASE UCASE$(BTN_EXIT$)
DoAskQuit
END SELECT
WEND
UIPop 1
FInitInfoDialog
ActionDetectPrinter = sz$
sz$ = ""
END FUNCTION
FUNCTION ActionDetectPorts STATIC AS INTEGER
DIM iSupportNet%
CursorSave% = ShowWaitCursor()
iSupportNet = 0
s$ = STRING$(32,64)
RemoveSymbol SYM_PORTSDESC$
i% = GetListLength(SYM_PORTNAMELIST$)
FOR j% = 5 TO i%
IF GetListItem(SYM_PORTSTATUSLIST$, j%) = VAL_CHKON$ THEN
lpwNetSize.size = 32
r$ = GetListItem(SYM_PORTNAMELIST$, j%)
k% = WNetGetConnection (r$, s$, lpwNetSize)
m% = FarGetPortAddr(j%-1)
IF j% <= 4 THEN
sz$ = GetListItem(SYM_COMPORTEXIST$, j%)
ELSE
sz$ = ""
END IF
IF (m% <> 0) AND (sz$ <> BTN_NO$) THEN
l% = OpenComm(r$, iIN_QUEUE%, iOUT_QUEUE%)
ELSE
l% = -10
END IF
IF l% >= 0 THEN
m% = CloseComm(l%)
END IF
IF (k% = WN_SUCCESS) OR (k% = WN_DEVICE_ERROR) OR (k% = WN_CONNECTION_CLOSED) THEN
ELSEIF l% >= 0 THEN
s$ = MSG_LOCAL$
ELSEIF l% = iIE_OPEN% THEN
s$ = MSG_BUSY$
ELSE
s$ = MSG_NOTPRESENT$
END IF
AddListItem SYM_PORTSDESC$, r$+" "+s$+" "
END IF
NEXT j%
i% = WNetGetCaps(6)
j% = WNetGetCaps(8)
IF ((i% AND 4) <> 0) AND ((j% AND 69) <> 0) THEN
iSupportNet = j%
END IF
s$ = ""
r$ = ""
ActionDetectPorts = iSupportNet
RestoreCursor CursorSave%
CursorSave% = 0
END FUNCTION
SUB CheckCartCode STATIC
DIM lCartCode&, bAtLeastOne%
cItem% = GetListLength(SYM_PORTNAMELIST$)
bAtLeastOne = FALSE
FOR i% = 5 TO cItem%
j% = GetListLength(GetListItem(SYM_PORTNAMELIST$, i%))
IF j% > 2 THEN
list$ = GetListItem(SYM_PORTNAMELIST$, i%)
lCartCode = VAL(GetListItem(list$, 8))
IF CompareVersion(lCartCode, GetListItem(list$, 2), list$) THEN
s$ = STRING$(32,64)
lpwNetSize.size = 32
k% = WNetGetConnection(list$, s$, lpwNetSize)
IF (k% = WN_SUCCESS) OR (k% = WN_DEVICE_ERROR) OR (k% = WN_CONNECTION_CLOSED) THEN
FInitInfoDialog
AddListItem SYM_STATUSITEMSTEXT$, list$
AddListItem SYM_STATUSITEMSTEXT$, list$
InfoDlgAOneButton BTN_OK$, IGNORE_REDIRECT, HELP_IGNORE_REDIRECT
END IF
s$ = ""
bAtLeastOne = TRUE
ELSE
RemoveSymbol list$
END IF
END IF
NEXT i%
IF bAtLeastOne = FALSE THEN
DoInCompatQuit
END IF
list$ = ""
END SUB
FUNCTION EditPrinterConfigInfo(lCartCode AS LONG) STATIC AS INTEGER
EditPrinterConfigInfo = FALSE
IF InvalidVersionCode((lCartCode)) THEN
DlgInvalidVersionCode
ELSE
RemoveSymbol SYM_TEMPLIST$
sz$ = MID$(PortAdding$, 1, 5)
SetSymbolValue sz$, MID$(PortAdding$, 6)
AddListItem sz$, DEFAULT_NAME$
AddListItem sz$, GetListItem(SYM_LISTITEMSOUT$, 1)
MakeListFromSectionKeys SYM_TEMPLIST$, VAL_PRINTERS$
PrinterAddingIndex% = VAL(GetListItem(SYM_LISTITEMSIN$, 2))
SetSymbolValue SYM_TEMPLIST$, GetListItem(SYM_TEMPLIST$, PrinterAddingIndex%)
AddListItem sz$, GetListItem(SYM_TEMPLIST$, 1)
AddListItem sz$, GetListItem(SYM_LISTITEMSOUT$, 2)
AddListItem sz$, "0"
AddListItem sz$, "0"
IF CompareVersion(lCartCode, GetListItem(SYM_LISTITEMSIN$, 1), sz$) THEN
AddListItem sz$, STR$(lCartCode)
ELSE
RemoveSymbol sz$
DoInCompatQuit
END IF
EditPrinterConfigInfo = TRUE
END IF
sz$ = ""
END FUNCTION
FUNCTION CompareVersion(lCode&, InstPrinterName$, InstPort$) STATIC AS INTEGER
DIM iVc%, iRc%, iRh%, iVh%
DIM iRet%
iRet = FALSE
IF lCode <> VAL(DEFAULT_COMPAT$) THEN
GetSepVersion lCode, iVc, iRc
iVh = VAL(DEFAULT_VERSION$)
iRh = VAL(DEFAULT_RH$)
FInitVersionDialog InstPrinterName$, InstPort$
IF (iVh = iVc) THEN
iRet = TRUE
ELSEIF (iVh > iVc) THEN
IF (iVc >= iRh) THEN
InfoDlgAOneButton BTN_CONTINUE$, UPDATE_CART, HELP_UPDATE_CART
iRet = TRUE
ELSE
InfoDlgAOneButton BTN_CONTINUE$, INCOMPAT_CART, HELP_INCOMPAT_CART
END IF
ELSE
IF (iVh >= iRc) THEN
InfoDlgAOneButton BTN_CONTINUE$, UPDATE_DRIVER, HELP_UPDATE_DRIVER
iRet = TRUE
ELSE
InfoDlgAOneButton BTN_CONTINUE$, INCOMPAT_DRIVER, HELP_INCOMPAT_DRIVER
END IF
ENDIF
ELSE
iRet = TRUE
ENDIF
CompareVersion = iRet
END FUNCTION
SUB GetSepVersion(lCode&, iCart%, iHost%) STATIC
DIM lTemp&
lTemp = lCode / 10
iCart = lTemp / 100
iHost = lTemp MOD 100
END SUB
